<template>
	<uni-popup ref="wxprivacy" type="center" :isMaskClick="false">
		<view class="wx-Privacy">
			<view class="title">
				用户隐私保护提示
			</view>
			<view class="tips">
				感谢您使用《延续随访》小程序，您使用本小程序前应当阅读并同意
			</view>
			<view class="privacy-protocol" @tap="openPrivacyContract">
				《用户隐私保护指引》
			</view>
			<view class="tips">
				当您点击同意并开始使用用产品服务时，即表示你已理解并同息该条款内容，该条款将对您产生法律约束力。如您拒绝，将无法进入享用我们提供的服务。
			</view>

			<button id="agree-btn" type="primary" open-type="agreePrivacyAuthorization" class="agree-btn"
				@agreeprivacyauthorization="handleAgree">同意</button>
		</view>
	</uni-popup>
</template>

<script>
	export default {
		name: "popWxPrivacy",
		data() {
			return {
				callBack: null,
			}
		},
		mounted() {
		},
		methods: {
			
			show() {
				return new Promise((resolve, reject) => {
					// #ifdef MP-WEIXIN
					if (!wx.getPrivacySetting) {
						console.log("小程序版本过低，没有getPrivacySetting")
						 resolve(true)//版本过低直接返回true
						 return
					}
					wx.getPrivacySetting({
						success: async (res) => {
							if (res.needAuthorization) { //需要弹窗隐私提示
								this.callBack = () => {
									this.callBack = null
									this.$refs.wxprivacy.close()
									resolve(true)
								}
								
							} else {
								this.$refs.wxprivacy.close()
								this.callBack = null
								// 用户已经同意过隐私协议，所以不需要再弹出隐私协议；弹窗获取手机号
								resolve(true)
							}
						}
					})
					// #endif

					// #ifndef MP-WEIXIN
					resolve(true)//非微信小程序默认同意
					// #endif
				});

			},
			openPrivacyContract() {
				// 打开隐私政策协议页面
				wx.openPrivacyContract({
					success: res => {
						console.log('openPrivacyContract success')
					},
					fail: res => {
						console.error('openPrivacyContract fail', res)
					}
				})
			},
			handleAgree() {
				if (this.callBack) {
					this.callBack()
				} else {
					this.$refs.wxprivacy.close()
					this.callBack = null
					this.$emit("succeed", true);
				}
			},
		}
	}
</script>

<style scoped lang="less">
	.wx-Privacy {
		background-color: white;
		border-radius: 20rpx;
		padding: 30rpx;
		width: calc(100vw * 0.618);
		color: #333;

		.title {
			font-size: 30rpx;
			color: rgba(0, 0, 0, 0.85);
			text-align: center;
			margin-bottom: 20rpx;
		}

		.tips {
			font-size: 26rpx;
			color: rgba(0, 0, 0, 0.65);
		}

		.privacy-protocol {
			font-size: 30rpx;
			color: blue;
			margin: 20rpx 0;

		}

		.agree-btn {

			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 30rpx;

			margin-top: 30rpx;
		}
	}
</style>